Class 6 Exam  >  Class 6 Questions  >  What will be the output of the following C co... Start Learning for Free
What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        printf("sanfoundry\rclass\n");
        return 0;
    }
  • a)
    sanfoundryclass
  • b)
    sanfoundry
    class
  • c)
    classundry
  • d)
    sanfoundry
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
What will be the output of the following C code? #include <stdio.h...
r is carriage return and moves the cursor back. sanfo is replaced by class.
Output:
$ cc pgm8.c
$ a.out
classundry
Free Test
Community Answer
What will be the output of the following C code? #include <stdio.h...
Understanding the Code
The provided C code snippet is:
c
#include
int main() {
printf("sanfoundry\rclass\n");
return 0;
}
Key Elements of the Code
- Header Inclusion: The code includes the standard input-output library `` which is necessary for using the `printf` function.
- Main Function: The `main` function is the entry point of the program.
- Printf Function: The `printf` function is used to print formatted output to the console.
Escape Sequences
- \r (Carriage Return): This escape sequence moves the cursor back to the beginning of the line without advancing to the next line.
- \n (New Line): This escape sequence advances the cursor to the next line after printing the output.
Execution Flow
1. The string "sanfoundry" is printed first.
2. The `\r` escape sequence then moves the cursor back to the start of the line.
3. Next, "class" is printed, overwriting the beginning of "sanfoundry" due to the carriage return.
4. Finally, `\n` moves the cursor to the next line.
Final Output Explanation
- The output will display as follows:
classundry
Here, "class" overwrites the "sanf" part of "sanfoundry", resulting in "classundry" being printed.
Correct Option
Thus, the correct answer is option 'C': classundry.
Explore Courses for Class 6 exam
Question Description
What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? for Class 6 2025 is part of Class 6 preparation. The Question and answers have been prepared according to the Class 6 exam syllabus. Information about What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Class 6 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer?.
Solutions for What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 6. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.
Here you can find the meaning of What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; }a)sanfoundryclassb)sanfoundryclassc)classundryd)sanfoundryCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Class 6 tests.
Explore Courses for Class 6 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev